<template>
  <div class="app-container">
    <div
      v-show="
        !modifyInfo.visible && !detailInfo.visible && !detailListInfo.visible
      "
    >
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <new-page-filter
          v-model:query="filterInfo.query.queryMap"
          :query-more-json="true"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :slip-select-request="slipSelectRequest"
          :clear-type="clearType"
        >
        </new-page-filter>
        <el-button @click="detailListInfo.visible = true">明细页</el-button>
      </div>
      <div class="filter-wrapper">
        <new-page-filter :filter-btn="filterInfo.btnList">
          <template v-slot:filter-submit>
            <el-button :disabled="!canSubmit" @click="submit()">提交</el-button>
          </template>
          <template v-slot:filter-ratify>
            <el-button :disabled="!canRatify" @click="ratify()">审核</el-button>
          </template>
          <template v-slot:filter-review>
            <el-button :disabled="!canReview" @click="review()">复核</el-button>
          </template>
          <template v-slot:filter-remove>
            <el-button :disabled="!canRemove" @click="del()">删除</el-button>
          </template>
        </new-page-filter>
        <div class="display-flex flex-end">
          <el-button @click="preferenceInfo.visible = true">偏好设置</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <table-container
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :row-class-name="tableRowClassName"
        :handle="tableInfo.handle"
        @handleEvent="handleEvent"
        @sortChange="sortChange"
        ><template v-slot:col-consumeOrderNo="scope">
          <span
            v-if="scope.row.consumeOrderNo"
            v-for="(item, index) in getOrderNoList(scope.row.consumeOrderNo)"
            class="slip-edit"
            :key="item"
            @click="toSourceDetail(proxy, item)"
            >{{ item }}
            {{
              scope.row.consumeOrderNo.includes(',')
                ? getOrderNoList(scope.row.consumeOrderNo).length !== index + 1
                  ? ','
                  : ''
                : ''
            }}</span
          >
          <span v-else>-</span>
        </template>
        <template v-slot:col-orderNo="scope">
          <span class="slip-edit" @click="showDetail(scope.row)">{{
            scope.row.orderNo || '-'
          }}</span>
        </template>
      </table-container>
    </div>
    <consume-order-detail
      v-if="detailInfo.visible"
      :id="detailInfo.id"
      v-model:visible="detailInfo.visible"
      page-type="consume"
      @returnBack="getList"
    />
    <detailList
      v-if="detailListInfo.visible"
      v-model:visible="detailListInfo.visible"
      :query="detailListInfo.query"
      :fromType="detailListInfo.fromType"
      @callback="detailListBack"
    ></detailList>
    <set-preference
      v-if="preferenceInfo.visible"
      v-model:visible="preferenceInfo.visible"
      :search-list="filterInfo.searchList"
      :field-list="tableInfo.fieldList"
      :customize-user-v-o="filterInfo.query.customizeUserVO"
      :group-level-show="false"
      @callback="setPreferenceCallback"
    />
    <advanced-search
      v-if="advancedSearchInfo.visible"
      v-model:visible="advancedSearchInfo.visible"
      v-model:form-data="advancedSearchInfo.data"
      :field-list="tableInfo.fieldList"
      @callback="advancedSearchCallback"
    />
    <Modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :orderId="modifyInfo.orderId"
      :title="modifyInfo.title"
      @returnModify="getList"
    />
    <chose-printer
      :visible="printerInfo.visible"
      @callBack="handlePrinterCallBack"
    />
    <page-dialog
      v-show="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <div class="asset-msg">
        <div class="asset-msg-label">
          <i class="el-icon-warning"></i>{{ dialogInfo.msg }}：
        </div>
        <el-radio-group v-model="dialogInfo.flag">
          <el-radio :label="true">当前页数据</el-radio>
          <el-radio :label="false">全部页数据</el-radio>
        </el-radio-group>
      </div>
    </page-dialog>
    <!-- 确认路径弹窗 -->
    <page-dialog
      v-if="dialogInfoPath.visible"
      :title="dialogInfoPath.title"
      v-model:visible="dialogInfoPath.visible"
      :width="dialogInfoPath.width"
      :bt-loading="dialogInfoPath.btLoading"
      :bt-list="dialogInfoPath.btList"
      @reset="close"
    >
      <dialog-table
        v-model:data="dialogTableInfo.data"
        :field-list="dialogTableInfo.fieldList"
        :highlight-row="true"
        :tab-index="true"
        :check-box="false"
        :pager="false"
        @handleEvent="handleDialogEvent"
      >
      </dialog-table>
    </page-dialog>
  </div>
</template>

<script setup name="consignConsumeConfirmOrder">
import {
  printListConsignConsumeConfirmOrder,
  excelListConsignConsumeConfirmOrder,
  reviewConsignConsumeConfirmOrder,
  getConsignConsumeConfirmOrderCustomizeListPage,
  deleteConsignConsumeConfirmOrder,
  backConsignConsumeConfirmOrder,
  cancelConsignConsumeConfirmOrder,
  confirmConsignConsumeConfirmOrder,
  confirmCancelConsignConsumeConfirmOrder,
  rejectConsignConsumeConfirmOrder,
  revokeConsignConsumeConfirmOrder,
  submitConsignConsumeConfirmOrder,
  ratifyConsignConsumeConfirmOrder,
  getConfirmPath,
  confirmByPath,
} from '@/api/stock'
import { getCustomizeSetting, updateUserCustomize } from '@/api/customize'
import Modify from './modify'
import moment from 'moment'
import { fatchTemplateByCode } from '@/api/base'
import { toSourceDetail } from '@/common/js/base.js'
const ConsumeOrderDetail = defineAsyncComponent(() => import('./detail'))
const detailList = defineAsyncComponent(() => import('./detailList'))
const route = useRoute()
const { proxy } = getCurrentInstance()

const page = ref({
  curPage: 1, // 当前页
  pageSize: 20, // 每页条数
})
const filterInfo = ref({
  sortArr: [],
  copyQueryMap: {},
  query: {
    sortString: '',
    // isPagerByPrint: true, //打印是否分页
    // isPagerByExport: false, //导出是否分页
    queryMap: {
      depotAuth: {
        asTbName: 'consign_consume_confirm_order',
        columnName: 'depot_id',
        queryType: 'IN',
        queryCategory: 'AND',
        value: 'depotAuth',
      },
    },
    customizeUserVO: {},
  },
  searchList: [],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '高级查询', event: advancedSearchShow },
    { type: 'button', label: '重置', event: clearSearch },
  ],
  btnList: [
    {
      type: 'button',
      label: '新增',
      event: create,
      show: proxy.$permission('consignConsumeConfirmOrder:add'),
    },
    {
      type: 'slot',
      label: '提交',
      value: 'submit',
      show: proxy.$permission('consignConsumeConfirmOrder:submit'),
    },
    {
      type: 'slot',
      label: '审核',
      value: 'ratify',
      show: proxy.$permission('consignConsumeConfirmOrder:ratify'),
    },
    {
      type: 'slot',
      label: '复核',
      value: 'review',
      show: proxy.$permission('consignConsumeConfirmOrder:review'),
    },
    {
      type: 'slot',
      label: '删除',
      value: 'remove',
      show: proxy.$permission('consignConsumeConfirmOrder:remove'),
    },
    {
      type: 'button',
      label: '打印',
      event: print,
      show: proxy.$permission('consignConsumeConfirmOrder:printList'),
    },
    {
      type: 'button',
      label: '导出excel',
      event: exportExcel,
      show: proxy.$permission('consignConsumeConfirmOrder:excelList'),
    },
  ],
})
const time = ref([])
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  api: undefined,
  data: [],
  selections: [],
  summaryFieldList: [
    { value: 'sumAmount', formatter: proxy.$fn.TripartiteMethod },
  ],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '修改',
        event: update,
        show: proxy.$permission('consignConsumeConfirmOrder:update'),
        ifRender: function (row) {
          return row.status === 1
        },
      },
      {
        label: '提交',
        event: submit,
        show: proxy.$permission('consignConsumeConfirmOrder:submit'),
        ifRender: function (row) {
          return row.status === 1
        },
      },

      {
        label: '审核',
        event: ratify,
        show: proxy.$permission('consignConsumeConfirmOrder:ratify'),
        ifRender: function (row) {
          return row.status === 2
        },
      },
      {
        label: '复核',
        event: review,
        show: proxy.$permission('consignConsumeConfirmOrder:review'),
        ifRender: function (row) {
          return row.status === 3
        },
      },
      {
        label: '确认',
        event: confirm,
        show: proxy.$permission('consignConsumeConfirmOrder:confirm'),
        ifRender: function (row) {
          return row.status === 4
        },
      },
      {
        label: '取消确认',
        event: confirmCancel,
        show: proxy.$permission('consignConsumeConfirmOrder:confirmCancel'),
        ifRender: function (row) {
          return row.status === 5
        },
      },
      {
        label: '删除',
        event: del,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: proxy.$permission('consignConsumeConfirmOrder:remove'),
        ifRender: function (row) {
          return row.status === 1
        },
      },
      {
        label: '驳回',
        event: reject,
        popconfirmText: '驳回后将改变数据,是否继续？',
        show: proxy.$permission('consignConsumeConfirmOrder:reject'),
        ifRender: function (row) {
          return row.status === 2
        },
      },
      {
        label: '撤回',
        event: revoke,
        popconfirmText: '撤回后将改变数据,是否继续？',
        show: proxy.$permission('consignConsumeConfirmOrder:revoke'),
        ifRender: function (row) {
          return row.status === 2 || row.status === 3 || row.status === 4
        },
      },
      {
        label: '退回',
        event: goBack,
        popconfirmText: '退回后将改变数据,是否继续？',
        show: proxy.$permission('consignConsumeConfirmOrder:goBack'),
        ifRender: function (row) {
          return row.status === 3
        },
      },
      {
        label: '取消',
        event: cancel,
        popconfirmText: '取消后将改变数据,是否继续？',
        show: proxy.$permission('consignConsumeConfirmOrder:cancel'),
        ifRender: function (row) {
          return row.status === 4
        },
      },
    ],
  },
})
const detailInfo = ref({
  visible: false,
  id: '',
})
const detailListInfo = ref({
  visible: false,
  fromType: '',
  query: {},
})
const preferenceInfo = ref({
  visible: false,
})
const advancedSearchInfo = ref({
  visible: false,
  data: {},
})
const clearType = ref(true)
const slipSelectRequest = ref(true)
const modifyInfo = ref({
  visible: false,
  title: '',
  orderId: '',
})
const dialogInfo = ref({
  visible: false,
  title: '提示',
  btLoading: false,
  type: '',
  msg: '',
  width: '400px',
  flag: true,
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '打印',
      type: 'primary',
      event: checkConfirm,
      show: true,
    },
  ],
})
const dialogTableInfo = ref({
  data: [],
  fieldList: [{ label: '移库路径', value: 'name' }],
})
const dialogInfoPath = ref({
  title: '移库路径',
  visible: false,
  type: '',
  width: '670px',
  btLoading: false,
  row: {},
  path: {},
  btList: [
    { label: '关闭', type: '', icon: '', event: closePath, show: true },
    {
      label: '保存',
      type: 'primary',
      icon: '',
      disabled: true,
      event: confirmByPathFun,
      saveLoading: false,
      show: true,
    },
  ],
})
const printerInfo = ref({
  visible: false,
  data: {},
})

const canRemove = computed(() => {
  return (
    tableInfo.value.selections.length &&
    tableInfo.value.selections.filter((row) => row.status !== 1).length === 0
  )
})
const canSubmit = computed(() => {
  return (
    tableInfo.value.selections.length &&
    tableInfo.value.selections.filter((row) => row.status !== 1).length === 0
  )
})
const canRatify = computed(() => {
  return (
    tableInfo.value.selections.length &&
    tableInfo.value.selections.filter((row) => row.status !== 2).length === 0
  )
})
const canReview = computed(() => {
  return (
    tableInfo.value.selections.length &&
    tableInfo.value.selections.filter((row) => row.status !== 3).length === 0
  )
})

watch(
  () => dialogInfoPath.value.visible,
  (val) => {
    if (!val) {
      dialogInfoPath.value.btList[1].disabled = true
    }
  }
)

watch(
  () => route,
  async () => {
    const params = route.params
    if (route.name === 'consignConsumeConfirmOrder') {
      if (await Object.keys(params).length) {
        detailListInfo.value['visible'] = false
        detailInfo.value.id = ''
        detailInfo.value.visible = false
        preferenceInfo.value.visible = false
        advancedSearchInfo.value.visible = false
        advancedSearchInfo.value.data = {}
        detailListInfo.value.fromType = 'route'
        if (params.fromType === 'yesterdayAmount') {
          let startDate =
            new Date(new Date(new Date().toLocaleDateString()).getTime()) -
            24 * 60 * 60 * 1000
          let endDate =
            new Date(
              new Date(new Date().toLocaleDateString()).getTime() +
                24 * 60 * 60 * 1000 -
                1
            ) -
            24 * 60 * 60 * 1000
          startDate = moment(startDate).format('YYYY-MM-DD HH:mm:ss')
          endDate = moment(endDate).format('YYYY-MM-DD HH:mm:ss')
          detailListInfo.value.query = {
            consumeDeptId: {
              queryType: 'IN',
              value: params.consumeDeptId,
            },
            consumeTime: {
              queryType: 'BETWEEN',
              value: `${startDate},${endDate}`,
            },
          }
          proxy.$nextTick(() => {
            detailListInfo.value['visible'] = true
          })
        } else if (params.fromType === 'usage') {
          let consumeTime = undefined
          if (params.code === 'year') {
            consumeTime = getMonthDateRange(moment().year(), params.date)
          } else if (
            params.code === 'months' ||
            params.code === 'month' ||
            params.code === 'week'
          ) {
            consumeTime = getDateRange(params.date)
          }
          detailListInfo.value.query = {
            financialAccount: {
              queryType: 'IN',
              value: params.type === 'all' ? '' : params.type,
            },
            consumeTime: {
              queryType: 'BETWEEN',
              value: `${consumeTime.start},${consumeTime.end}`,
            },
          }
          proxy.$nextTick(() => {
            detailListInfo.value['visible'] = true
          })
        }
      }
    }
  },
  {
    immediate: true,
  }
)
const toPage = computed(() => {
  return proxy.$store.state.settings.toPage
})
let stopWatch = function () {}
onActivated(() => {
  stopWatch = watch(
    () => toPage.value,
    (val) => {
      if (val) {
        let menus = proxy.$store.state.permission.defaultMenus
        menus.forEach((item) => {
          if (item.children) {
            item.children.forEach((el) => {
              if (
                el.code === 'consignConsumeConfirmOrder' &&
                el.url === val.url
              ) {
                modifyInfo.value.visible = false
                detailInfo.value.visible = false
                if (val.urlType === 1) {
                  getList()
                } else if (val.urlType === 2) {
                  proxy.$nextTick(() => {
                    detailInfo.value.visible = true
                    detailInfo.value.id = val.businessId
                    sessionStorage.setItem('storeRowId', val.businessId)
                  })
                }
                proxy.$store.dispatch('settings/toPage', '')
              }
            })
          }
        })
      }
    },
    {
      deep: true,
      immediate: true,
    }
  )
})
onDeactivated(() => {
  stopWatch()
})
setData()
function setData() {
  let obj = {
    statusValue: {
      label: '状态',
      value: 'statusValue',
      asValue: 'status',
      componentType: 'select-model',
      code: 'consign_consume_confirm_order_status',
      show: false,
      hidden: true,
    },
    sumAmount: {
      label: '总金额',
      value: 'sumAmount',
      formatter: proxy.$fn.TripartiteMethod,
      type: 'column',
      componentType: 'price',
      permission: !proxy.$permission('consignConsumeConfirmOrder:price'),
      hidden: true,
      show: false,
    },
    consumeOrderNo: {
      label: '来源消耗单号',
      value: 'consumeOrderNo',
      type: 'slot',
      show: false,
      hidden: true,
    },
  }
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  filterInfo.value.searchList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  getCustomize()
}
function pageInfo(obj) {
  page.value = obj
}
function handleClose() {
  dialogInfo.value.visible = false
}
function _getIds(row) {
  let ids = []
  if (row && row.id) {
    ids = [row.id]
  } else {
    if (tableInfo.value.selections.length > 0) {
      ids = tableInfo.value.selections.map((row) => row.id)
    }
  }
  return ids
}
function getOrderNoList(val) {
  if (!val) return []
  if (val.includes(',')) {
    return val.split(',')
  }
  return [val]
}
//创建
function create() {
  modifyInfo.value.title = '新增寄售消耗确认单'
  modifyInfo.value.visible = true
  modifyInfo.value.orderId = null
}
//更新
function update(row) {
  modifyInfo.value.title = '修改寄售消耗确认单'
  modifyInfo.value.orderId = row.id
  modifyInfo.value.visible = true
}
//提交
function submit(row) {
  const ids = _getIds(row)
  submitConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//驳回
function reject(row) {
  const ids = [row.id]
  rejectConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function goBack(row) {
  //退回
  const ids = [row.id]
  backConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function handleDialogEvent(event, data) {
  if (event === 'tableClickRow') {
    dialogInfoPath.value.btList[1].disabled = false
    dialogInfoPath.value.path = data.value
  }
}
function confirm(row) {
  getConfirmPath(row.id).then((res) => {
    if (!res.data.length) {
      //确认
      confirmConsignConsumeConfirmOrder(row.id).then((resp) => {
        if (resp && resp.success) {
          getList()
        }
      })
    }
    if (res.data.length === 1) {
      _confirmByPath({ id: row.id, path: res.data[0].value })
    }
    if (res.data.length > 1) {
      dialogTableInfo.value.data = res.data
      dialogInfoPath.value.visible = true
      dialogInfoPath.value.row = row
    }
  })
}

function confirmCancel(row) {
  //取消确认
  confirmCancelConsignConsumeConfirmOrder(row.id).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function confirmByPathFun() {
  confirmByPath({
    id: dialogInfoPath.value.row.id,
    path: dialogInfoPath.value.path,
  }).then((resp) => {
    if (resp && resp.success) {
      dialogInfoPath.value.visible = false
      getList()
    }
  })
}
function _confirmByPath(params) {
  confirmByPath(params).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function closePath() {
  dialogInfoPath.value.visible = false
}
//审核
function ratify(row) {
  const ids = _getIds(row)
  ratifyConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function review(row) {
  //复核
  const ids = _getIds(row)
  reviewConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//撤回
function revoke(row) {
  const ids = [row.id]
  revokeConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//取消
function cancel(row) {
  const ids = [row.id]
  cancelConsignConsumeConfirmOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//删除
function del(row = undefined) {
  const ids = _getIds(row)
  if (row && row.id) {
    deleteConsignConsumeConfirmOrder(ids).then((resp) => {
      if (resp && resp.success) {
        getList()
      }
    })
  } else {
    proxy
      .$confirm('删除后将改变数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        deleteConsignConsumeConfirmOrder(ids).then((resp) => {
          if (resp && resp.success) {
            getList()
          }
        })
      })
  }
}
function getMonthDateRange(year, number) {
  let month = number.slice(5, 7)
  let startDate = new Date(year, month - 1, 1).getTime()
  let endDate = new Date(year, month, 0).getTime() + 24 * 60 * 60 * 1000 - 1
  startDate = moment(startDate).format('YYYY-MM-DD HH:mm:ss')
  endDate = moment(endDate).format('YYYY-MM-DD HH:mm:ss')
  return { start: startDate, end: endDate }
}
function getDateRange(str) {
  let date = str.replace(/[^0-9]/gi, '-').split('-')
  let newDate = date[0] + '-' + date[1] + '-' + date[2]
  let startDate = new Date(newDate).getTime() - 3600 * 1000 * 8
  let endDate = new Date(newDate).getTime() + 16 * 3600 * 1000 - 1
  startDate = moment(startDate).format('YYYY-MM-DD HH:mm:ss')
  endDate = moment(endDate).format('YYYY-MM-DD HH:mm:ss')
  return { start: startDate, end: endDate }
}
function detailListBack() {
  getList()
  detailListInfo.value.fromType = ''
  detailListInfo.value.query = {}
}
function setPreferenceCallback(obj) {
  updateUserCustomize(obj.customizeUserVO).then((res) => {
    if (res && res.success) {
      getCustomize(!slipSelectRequest.value)
    }
  })
}
function advancedSearchShow() {
  advancedSearchInfo.value.visible = true
}
async function advancedSearchCallback(obj) {
  let arr = [
    {
      fieldName: 'deptId',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'deptAuth',
    },
  ]
  filterInfo.value.query.queryMap = {}
  filterInfo.value.query.queryDtoList = [...obj.queryDtoList, ...arr]
  advancedSearchInfo.value.data = obj.data
  await getList()
  clearType.value = !clearType.value
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
}
async function getList() {
  tableInfo.value.refresh = Math.random()
}
function search() {
  advancedSearchInfo.value.data = {}
  filterInfo.value.query.queryDtoList = []
  tableInfo.value.initCurpage = Math.random()
  tableInfo.value.refresh = Math.random()
}
function showDetail(row) {
  sessionStorage.setItem('storeRowId', row.id)
  detailInfo.value.id = row.id
  detailInfo.value.visible = true
}
function tableRowClassName({ row }) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  }
  return ''
}
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.value.selections = [...data]
      break
  }
}
function timeChange(val) {
  if (val && val.length) {
    filterInfo.value.query.queryMap.consumeTime.value = `${val[0]},${val[1]}`
  } else {
    filterInfo.value.query.queryMap.consumeTime.value = ''
  }
}
function clearSearch() {
  clearType.value = !clearType.value
  time.value = []
  advancedSearchInfo.value.data = {}
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
  search()
}
function getCustomize(_slipSelectRequest = true) {
  let _tableInfo = tableInfo.value
  let _filterInfo = filterInfo.value
  let param = {
    tableKey:
      'consignConsumeConfirmOrderList-com.slip.spd.entity.vo.stock.ConsignConsumeConfirmOrderVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      _tableInfo.fieldList = proxy.$fn.setFieldList(
        _tableInfo.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        _filterInfo.searchList,
        data.detail
      )
      _filterInfo.query.queryMap = {
        ...searchInfo.queryMap,
        ..._filterInfo.query.queryMap,
      }
      _filterInfo.searchList = searchInfo.searchList
      _filterInfo.searchList.forEach((item) => {
        item.event = search
      })
      filterInfo.value.copyQueryMap = proxy.$fn.deepClone(
        filterInfo.value.query.queryMap
      )
      slipSelectRequest.value = _slipSelectRequest
      _tableInfo.api = getConsignConsumeConfirmOrderCustomizeListPage
      getList()
    }
  })
}
function sortChange(column) {
  let _filterInfo = filterInfo.value
  if (_filterInfo.query.customizeUserVO.head.sortType === 0) {
    let arr = proxy.$fn.sortChange(column, _filterInfo.sortArr)
    _filterInfo.sortArr = arr
    _filterInfo.query.sortString = arr.length ? arr.toString() : ''
    getList()
  }
}
function handlePrinterCallBack(printer) {
  if (printer !== false) {
    proxy.$print.buildRenderBarCode(printerInfo.value.data, printer)
  }
  printerInfo.value.visible = false
}
function checkConfirm() {
  if (dialogInfo.value.type === 'excel') {
    exportExcelList()
  } else if (dialogInfo.value.type === 'print') {
    printList()
  }
  dialogInfo.value.visible = false
  dialogInfo.value.msg = ''
}
function exportExcel() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'excel'
  dialogInfo.value.msg = '请选择数据导出范围'
  dialogInfo.value.btList[1].label = '导出'
  dialogInfo.value.flag = true
}
function exportExcelList() {
  let params = {
    ...filterInfo.value.query,
    ...page.value,
    page: dialogInfo.value.flag,
  }
  excelListConsignConsumeConfirmOrder(params).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
async function print() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'print'
  dialogInfo.value.msg = '请选择当数据打印范围'
  dialogInfo.value.btList[1].label = '打印'
  dialogInfo.value.flag = true
}
function printList() {
  fatchTemplateByCode({
    resourceCode: 'consignConsumeConfirmOrder:printList',
    isDefault: 1,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPrintData(temp, dialogInfo.value.flag)
    }
  })
}
function getPrintData(temp, flag) {
  let query = {
    customizeDto: filterInfo.value.query,
  }
  let params = {
    ...query,
    ...page.value,
    page: flag,
  }
  printListConsignConsumeConfirmOrder(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData)
    }
  })
}
</script>

<style scoped></style>
